package srebroa.unit.converter;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {	
	private EditText text_mm;
	private EditText text_mils;

    @Override
    // All code in this method is run when the application is starting
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text_mm = (EditText) findViewById(R.id.editText1);
        text_mils = (EditText) findViewById(R.id.editText2);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    public void convertTo_mm(View v){
        if (text_mils.getText().length() == 0) {
        	printAlert();
        	
        }
        else{
        	float mils = Float.parseFloat(text_mils.getText().toString());
        	float mm = (float) (0.0254*mils);    	
        	text_mm.setText(String.valueOf(mm));
        }    	
    }
    
    public void convertTo_mils(View v){
        if (text_mm.getText().length() == 0) {
        	printAlert();
        }	
        else{
        	float mm = Float.parseFloat(text_mm.getText().toString());
        	float mils = (float) (mm/0.0254);   	
        	text_mils.setText(String.valueOf(mils));
        }  	
    }
    
    private void printAlert(){
    	Toast.makeText(this, "Please enter a valid number",Toast.LENGTH_LONG).show();
    }
        
}// public class MainActivity extends Activity
